int reverse(int x)
{
    int temp1 = 0;
    int temp2 = 0;
    
    while(x != 0)
    {
        if (temp2 < -2147483648 / 10 || temp2 > 2147483647 / 10)
        {
            return 0;
        }

        temp1 = x % 10;
        x = x / 10;
        temp2 = temp2 * 10 + temp1;

    }
    return temp2;
}